import copy
import datetime
import heapq
import itertools
import json
import random
import sys
import time

import cv2
import numpy as np
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

from libs import config
from libs.action import WebDriverAction
from libs.cache import Cache
from libs.db import DB
from libs.game import Game, _get_snapshot_all
from libs.image import ImageTool
from libs.log import Log
from libs.movement import Movement, KeyCode
from libs.price import get_average_price, get_floor_price
from libs.scheduler_v2 import SchedulerV2
from libs.task_helper import TaskHelper
from libs.trade_helper import TradeHelper
from libs.window import AdsWindow

scheduler = SchedulerV2()
# task_id = scheduler.get_task_id(1, 'silk_slug_3450')
# last_finish_tiem = scheduler.get_last_finish_time(task_id)
# print(last_finish_tiem)

accounts = config.get_accounts()
# cache = Cache()
#
# cache.set(f'land_cooking_3450_1', 1, 0)
# sys.exit()

# Craft
for user_id in accounts:
    account = accounts.get(user_id)
    TaskHelper(user_id).add_task('craft.py', delay_seconds=0, ignore_running=False)

sys.exit()

# # Pixmas
# for user_id in config.get_accounts():
#     if int(user_id) in config.get_exclude_accounts():
#         continue
#     TaskHelper(user_id).add_task('pixmas_cookie.py', delay_seconds=0, ignore_running=False, priority=9)
#     # TaskHelper(user_id).add_task('pixmas_puzzle.py', delay_seconds=0, ignore_running=False, priority=9)
# sys.exit()

# # throw
# for user_id in config.get_accounts():
#     TaskHelper(user_id).add_task('throw.py', delay_seconds=0, ignore_running=False, priority=9)
# sys.exit()

# # WOOD
# for user_id in accounts:
#     account = accounts.get(user_id)
#     if account.get('is_vip', False) and account.get('wood', False):
#         TaskHelper(user_id).add_task('wood.py', delay_seconds=0, ignore_running=False)
# sys.exit()

# TaskHelper(105).add_task('collect.py', 0, False, False)
# TaskHelper(101).add_task('collect.py', 0, False, False)
# sys.exit()

# print(SchedulerV2().list_running_windows())
# sys.exit()

DB().run_sql("DELETE from item_price where item_name = ? ", ('Egg',))

sys.exit()

user_id = 4
log = Log(user_id)
driver = AdsWindow(user_id).open(False)
game = Game(driver, user_id)
action = WebDriverAction(driver)
ac = ActionChains(driver)
movement = Movement(driver)
image_tool = ImageTool(driver)
trade_helper = TradeHelper(driver, user_id)


game.enter_game()


# trade_helper.goto_buy_position()
# filter_input = trade_helper.open_market_buy()
# print(trade_helper.open_order_items(filter_input, 'Pet Treat'))
